#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5+1000;
typedef long long LL;
typedef pair<LL,LL>P;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL ans[maxn];
LL c[maxn];
struct E{
   LL id,val;
}a[maxn];
bool cmp(E A,E B){
    return A.val<B.val;
}
int main(void){
   cin.tie(0);std::ios::sync_with_stdio(false);
   LL t;cin>>t;
   while(t--){
      LL n,m,x;cin>>n>>m>>x;
      for(LL i=0;i<n+10;i++) ans[i]=0;
      LL sum=0;
      for(LL i=1;i<=n;i++) cin>>a[i].val,a[i].id=i;
      sort(a+1,a+1+n,cmp);
      LL temp=0;
      LL j=1;
      priority_queue<P,vector<P>,greater<P> >que;
      for(LL i=1;i<=m;i++){
          que.push({c[i],i});
      }
      while(j<=n){
        P now=que.top();que.pop();
       /// cout<<now.first<<" "<<now.second<<"\n";
        now.first+=a[j].val;
        ans[a[j].id]=now.second;
        que.push(now);
        j++;
      }
      LL mx=1e18;LL maxv=-1;
      for(LL i=1;i<=m;i++){
          mx=min(mx,c[i]);
          maxv=max(maxv,c[i]);
      }
      if(maxv-mx>x){
         cout<<"NO"<<"\n";
      }
      else{
         cout<<"YES"<<"\n";
         for(LL i=1;i<=n;i++){
             cout<<ans[i]<<" ";
         }
         cout<<"\n";
      }
   }
   return 0;
}
